package com.ruoyi.exam.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.exam.domain.req.ExamineReq;
import com.ruoyi.exam.domain.vo.ExamineVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.exam.domain.Examine;
import com.ruoyi.exam.service.IExamineService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考试管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/examine")
public class ExamineController extends BaseController
{
    @Autowired
    private IExamineService examineService;

    /**
     * 查询考试管理列表
     */
    @RequiresPermissions("exam:examine:list")
    @GetMapping("/list")
    public TableDataInfo list(Examine examine)
    {
        startPage();
        List<Examine> list = examineService.selectExamineList(examine);
        return getDataTable(list);
    }

    /**
     * 导出考试管理列表
     */
    @RequiresPermissions("exam:examine:export")
    @Log(title = "考试管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Examine examine)
    {
        List<Examine> list = examineService.selectExamineList(examine);
        ExcelUtil<Examine> util = new ExcelUtil<Examine>(Examine.class);
        util.exportExcel(response, list, "考试管理数据");
    }

    /**
     * 获取考试管理详细信息
     */
    @RequiresPermissions("exam:examine:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(examineService.selectExamineById(id));
    }

    /**
     * 新增考试管理
     */
    @RequiresPermissions("exam:examine:add")
    @Log(title = "考试管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamineVO examine)
    {
        return toAjax(examineService.addExam(examine));
    }

    /**
     * 修改考试管理
     */
    @RequiresPermissions("exam:examine:edit")
    @Log(title = "考试管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamineVO examine)
    {
        return toAjax(examineService.updateExamineVO(examine));
    }

    /**
     * 考试启用禁用
     */
    @RequiresPermissions("exam:examine:edit")
    @Log(title = "考试状态启用禁用", businessType = BusinessType.UPDATE)
    @PutMapping("/examEnable")
    public AjaxResult examEnable(Long id, Integer examStatus)
    {
        Examine examine = new Examine();
        examine.setId(id);
        examine.setExamStatus(examStatus);
        return toAjax(examineService.updateExamine(examine));
    }

    /**
     * 删除考试管理
     */
    @RequiresPermissions("exam:examine:remove")
    @Log(title = "考试管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examineService.deleteExamineByIds(ids));
    }



    @PostMapping("addExamine")
    @Validated
    public AjaxResult addExamine(@RequestBody ExamineReq examineReq)
    {
        return toAjax(examineService.addExamine(examineReq));
    }
}
